<?php
/**
* @version $Id: submit.php,v 1.1 2005/11/03 10:18:18 mic Exp $
* @package XfaQ - a frequently asked question component for Joomla! & Mambo CMS
* @copyright (C) 2005 mgfi.info
* @info info@mgfi.info http://www.mgfi.info
* @license GNU/GPL
* based in simplefaq 2.0.1 & glossary 1.4
*/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

// access only for superadmins & admins
if ( !( $acl->acl_check( 'administration', 'config', 'users', $my->usertype )) || $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'com_xfaq' )) {
	mosRedirect( 'index2.php', _NOT_AUTH );
}

require_once( $mainframe->getPath( 'admin_html' ) );
require_once( $mainframe->getPath( 'class' ) );

$cid = mosGetParam( $_POST, 'cid', array(0) );
if (!is_array( $cid )) {
	$cid = array(0);
}

$pathCom = $GLOBALS['mosConfig_absolute_path'] . '/administrator/components/com_xfaq/';
$pathComRel = $GLOBALS['mosConfig_live_site'] . '/administrator/components/com_xfaq/';
$pathLanguagesAdmin = $pathCom . 'languages/admin_';
$pathLanguagesUser = $GLOBALS['mosConfig_absolute_path'] . '/components/com_xfaq/languages/';

// call for correct language
if( !defined( '_XFAQ_ALANG_INCLUDED' )) {
	$tmp_lng = $GLOBALS['mosConfig_lang'];
	if( $mosConfig_alang ){
    	if( file_exists( $pathLanguagesAdmin . $mosConfig_alang . '.php' )) $tmp_lng = $mosConfig_alang;
	}
	if( file_exists( $pathLanguagesAdmin . $tmp_lng . '.php' )){
		include_once( $pathLanguagesAdmin . $tmp_lng . '.php' );
	}else{
		if( file_exists( $pathLanguagesAdmin . 'german.php' )) $tmp_lng = 'german.php'; else $tmp_lng = 'germanf.php';
    	include_once( $pathLanguagesAdmin . $tmp_lng );
	}
}

switch ($task) {

	case 'categories':
    	mosRedirect( 'index2.php?option=categories&section=com_xfaq' );
    	break;

  	case 'publish':
    	publishxFAQ( $cid, 1, $option );
    	break;

	case 'unpublish':
    	publishxFAQ( $cid, 0, $option );
    	break;

	case 'orderup':
		orderFAQ( $cid[0], -1, $option );
		break;

	case 'orderdown':
		orderFAQ( $cid[0], 1, $option );
		break;

	case 'saveorder':
		saveOrder( $cid, $option );
		break;

	case 'new':
    	editxFAQ( $option, $database, 0 );
    	break;

	case 'edit':
    	editxFAQ( $option, $database, $cid[0] );
    	break;

  	case 'remove':
    	removexFAQ( $database, $cid, $option );
    	break;

	case 'cancel':
		cancelxFAQ( $option );
		break;

	case 'save':
    	savexFAQ( $option, $database );
    	break;

	case 'config':
    	showConfig( $option );
    	footerFaq();
    	break;

	case 'savesettings':
    	saveConfig ($option);
    	break;

  	default:
    	showxFAQ( $option, $database );
    	break;
}

// Show footer on Admin page (not shown but as copyright here)
/* Copyright 2005 by http://www.parkviewconsultants.com */

// End of Main Admin loop

/* functions */

function footerFaq(){ ?>
    <p align="center">
        <span class="small" style="text-align: center; color:#999;"><a href="http://www.mgfi.info" target="_blank" title="Xfaq by MGFi.info">XfaQ v.<?php echo xfaq_this_version(); ?></a> by <a href="http://www.mgfi.info" target="_blank" title="MGFi">MGFi</a><br />(based on SimpleFAQ 2.0.1 from parkviewconsultants)</span>
    </p>
    <?php
}

function xfaq_this_version() {
	global $xfaq_version;

	$xfaq_version = '1.2';
	return $xfaq_version;
}

/** JJC
* Moves the order of a record
* @param integer The increment to reorder by
*/
function orderFAQ( $uid, $inc, $option ) {
	global $database;
	$row = new mosxFAQ( $database );
	$row->load( $uid );
	$row->move( $inc, 'published >= 0' );

	mosRedirect( 'index2.php?option=' . $option );
}

function saveOrder( &$cid, $option ) {
	global $database;

	$total		= count( $cid );
	$order 		= mosGetParam( $_POST, 'order', array(0) );
	$redirect 	= mosGetParam( $_POST, 'redirect', 0 );
	$rettask	= mosGetParam( $_POST, 'returntask', '' );
	$row 		= new mosxFAQ( $database );
	$conditions = array();

    // update ordering values
	for( $i=0; $i < $total; $i++ ) {
		$row->load( $cid[$i] );
		if ($row->ordering != $order[$i]) {
			$row->ordering = $order[$i];
	        if (!$row->store()) {
	            echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
	            exit();
	        } // if
	        // remember to updateOrder this group
	        $condition = "catid='$row->catid' AND state>=0";
	        $found = false;
	        foreach ( $conditions as $cond )
	            if ($cond[1]==$condition) {
	                $found = true;
	                break;
	            } // if
	        if (!$found) $conditions[] = array($row->id, $condition);
		} // if
	} // for

	// execute updateOrder for each group
	foreach ( $conditions as $cond ) {
		$row->load( $cond[0] );
		$row->updateOrder( $cond[1] );
	} // foreach

	$msg 	= _XFAQ_A_MESS_NEW_ORDER_SAVED;
	mosRedirect( 'index2.php?option=' . $option );
} // saveOrder


function showxFAQ( $option, &$db ) {
    global $database, $mainframe;

	$catid = $mainframe->getUserStateFromRequest( "catid{$option}", 'catid', 0 );
	$limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $GLOBALS['mosConfig_list_limit'] );
	$limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 );
	$search = $mainframe->getUserStateFromRequest( "search{$option}", 'search', '' );
	$search = $database->getEscaped( trim( strtolower( $search ) ) );

    $where = array();
    //if ($catid > 0) {
	//   $where[] = "catid='$catid'";
    //}
    if ($search) {
        $where[] = "LOWER(question) LIKE '%$search%'";
        $where[] = "LOWER(answer) LIKE '%$search%'";
    }

	// get the total number of records
	$database->setQuery( "SELECT count(*) FROM #__xfaq" );
	$total = $database->loadResult();

	require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
	$pageNav = new mosPageNav( $total, $limitstart, $limit  );

    // get the subset (based on limits) of required records
    $database->setQuery( "SELECT a.*, cc.name AS category"
	   . "\nFROM #__xfaq AS a"
	   . "\nLEFT JOIN #__categories AS cc ON cc.id = a.catid"
	   . (count( $where ) ? "\nWHERE " . implode( ' AND ', $where ) : "")
	   . "\nORDER BY a.catid, a.ordering, a.question"
	   . "\nLIMIT $pageNav->limitstart,$pageNav->limit"
  );

  $rows = $database->loadObjectList();
  if ($database->getErrorNum()) {
		echo $database->stderr();
		return false;
  }

	// build list of categories
	$javascript = 'onchange="document.adminForm.submit();"';
	$lists['catid'] = mosAdminMenus::ComponentCategory( 'catid', 'com_xfaq', intval( $catid ), $javascript );

	HTML_xFAQ::showxFAQEntries( $option, $rows, $search, $pageNav, $lists );
}

function removexFAQ( &$db, $cid, $option ) {
	if (count( $cid )) {
        $cids = implode( ',', $cid );
        $db->setQuery( "DELETE FROM #__xfaq WHERE id IN ($cids)" );
        if (!$db->query()) {
        	echo "<script> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
        }
  	}
  	mosRedirect( 'index2.php?option=' . $option );
}

function publishxFAQ( $cid=null, $publish=1,  $option ) {
  global $database;

  if (!is_array( $cid ) || count( $cid ) < 1) {
    $action = $publish ? _XFAQ_TO_PUBLISH : _XFAQ_TO_UNPUBLISH;
    echo "<script> alert('" . _XFAQ_SELECT_ITEM . $action . "'); window.history.go(-1);</script>\n";
    exit;
  }

  $cids = implode( ',', $cid );

  $database->setQuery( "UPDATE #__xfaq SET published='$publish' WHERE id IN ($cids)" );
  if (!$database->query()) {
    echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
    exit();
  }

  mosRedirect( 'index2.php?option=' . $option );
}

function editxFAQ( $option, &$db, $id ) {
  global $mosConfig_absolute_path, $mosConfig_live_site;

  $row = new mosxFAQ( $db );

  if ($id) {
    $db->setQuery( "SELECT * FROM #__xfaq WHERE id = $id" );
    $rows = $db->loadObjectList();;
    $row = $rows[0];
  } else {
    // initialise new record
	$row->imagepos = 'top';
    $row->published = 0;
    $row->ordering = 0;
  }

// make the select list for the image positions
  $yesno[] = mosHTML::makeOption( '0', _XFAQ_A_NO );
  $yesno[] = mosHTML::makeOption( '1', _XFAQ_A_YES );

//
// Stick the next bit in - but don't understand it yet
//
/*
    $lists = array();
	// build the html select list for ordering
	$query = "SELECT ordering AS value, name AS text"
	. "\n FROM #__xfaq"
	. "\n WHERE published >= 0"
	. "\n ORDER BY ordering"
	;
	$lists['ordering'] 			= mosAdminMenus::SpecificOrdering( $row, $id, $query, 1 );
*/

// Source: MOS - admin.weblinks.php
// get list of categories
	$categories[] = mosHTML::makeOption( '0', _XFAQ_A_SEL_CAT );
	$db->setQuery( "SELECT id AS value, name AS text FROM #__categories"
		. "\nWHERE section='com_xfaq' ORDER BY ordering" );
	$categories = array_merge( $categories, $db->loadObjectList() );

	if (count( $categories ) < 1) {
		mosRedirect( 'index2.php?option=categories&section=' . $option, _XFAQ_A_MESS_ADD_CAT_FIRST );
	}

	$clist = mosHTML::selectList( $categories, 'catid', 'class="inputbox" size="1"',
		'value', 'text', intval( $row->catid ) );

	// build the html select list
  	$publist = mosHTML::selectList( $yesno, 'published', 'class="inputbox" size="2"', 'value', 'text', $row->published );

  	HTML_xFAQ::editxFAQ( $option, $row, $publist, $clist );
}

/**
* Save operation
* @param string The current url option
*/
function savexFAQ( $option, &$db ) {
    global $my;

    $row = new mosxFAQ( $db );
    if (!$row->bind( $_POST )) {
        echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
        exit();
    }
    $row->_tbl_key = "id";

	// save params
	$params = mosGetParam( $_POST, 'params', '' );
	if (is_array( $params )) {
		$txt = array();
		foreach ( $params as $k=>$v) {
			$txt[] = "$k=$v";
		}
		$row->params = implode( "\n", $txt );
	}

    if (!$row->store()) {
        echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
        exit();
    }

	$row->checkin();
	$row->updateOrder();

    mosRedirect( 'index2.php?option=' . $option );
}


/**
* Cancels an edit operation
* @param string The current url option
*/
function cancelxFAQ( $option ) {
	mosRedirect( 'index2.php?option=' . $option . '&task=view', _XFAQ_A_EDIT_CANCELED );
}

/**
 * Shows config
 * Edits config
 * Saves config
**/
function showConfig( $option ) {
	$configfile = $GLOBALS['mosConfig_absolute_path'] . '/administrator/components/com_xfaq/config.xfaq.php';
	require_once( $configfile ); ?>
	<script type="text/javascript">
        function submitbutton(pressbutton) {
          var form = document.adminForm;
          if (pressbutton == 'cancel') {
            submitform( pressbutton );
            return;
          }
          if (form.xfaq_perpage.value == ""){
            alert( "<?php echo _XFAQ_A_ENTRIES_PER_PAGE; ?>" );
          } else {
            submitform( pressbutton );
          }
        }
    </script>
    <?php
    $xfaqMess = '';
    @chmod ($configfile, 0766);
    $permission = @is_writable($configfile);
    @chmod ($configfile, 0644);
    if (!$permission) {
        $xfaqMess = '<span style="color:red;">' . _XFAQ_CONFIG_NOT_WRITEABLE . '</span>';
    }else{
        $xfaqMess = '<span style="color:green;">' . _XFAQ_CONFIG_IS_WRITEABLE . '</span>';
    }

    mosCommonHTML::loadOverlib();

    // vars
    $yn_xfaq_indexmode = mosHTML::yesnoRadioList( 'xfaq[indexmode]', 'class="inputbox"', $xfaq['indexmode'] );
    $yn_xfaq_showsearch = mosHTML::yesnoRadioList( 'xfaq[showsearch]', 'class="inputbox"', $xfaq['showsearch'] );
    $yn_xfaq_showcategories = mosHTML::yesnoRadioList( 'xfaq[showcategories]', 'class="inputbox"', $xfaq['showcategories'] );
    $yn_xfaq_hideauthor = mosHTML::yesnoRadioList( 'xfaq[hideauthor]', 'class="inputbox"', $xfaq['hideauthor'] );
    $yn_xfaq_requestauthorname = mosHTML::yesnoRadioList( 'xfaq[requestauthorname]', 'class="inputbox"', $xfaq['requestauthorname'] );
    $yn_xfaq_requestauthorlocation = mosHTML::yesnoRadioList( 'xfaq[requestauthorlocation]', 'class="inputbox"', $xfaq['requestauthorlocation'] );
	$yn_xfaq_requestauthorhomepage = mosHTML::yesnoRadioList( 'xfaq[requestauthorhomepage]', 'class="inputbox"', $xfaq['requestauthorhomepage'] );
	$yn_xfaq_requestauthoremail = mosHTML::yesnoRadioList( 'xfaq[requestauthoremail]', 'class="inputbox"', $xfaq['requestauthoremail'] );
	$yn_xfaq_answermandatory = mosHTML::yesnoRadioList( 'xfaq[answermandatory]', 'class="inputbox"', $xfaq['answermandatory'] );
	$yn_xfaq_requestanswer = mosHTML::yesnoRadioList( 'xfaq[requestanswer]', 'class="inputbox"', $xfaq['requestanswer'] );
	$yn_xfaq_allowcomments = mosHTML::yesnoRadioList( 'xfaq[allowcomments]', 'class="inputbox"', $xfaq['allowcomments'] );
	$yn_xfaq_usehtmleditor = mosHTML::yesnoRadioList( 'xfaq[usehtmleditor]', 'class="inputbox"', $xfaq['usehtmleditor'] );
	$yn_xfaq_allowentry = mosHTML::yesnoRadioList( 'xfaq[allowentry]', 'class="inputbox"', $xfaq['allowentry'] );
	$yn_xfaq_anonentry = mosHTML::yesnoRadioList( 'xfaq[anonentry]', 'class="inputbox"', $xfaq['anonentry'] );
	$yn_xfaq_autopublish = mosHTML::yesnoRadioList( 'xfaq[autopublish]', 'class="inputbox"', $xfaq['autopublish'] );
	$yn_xfaq_notify = mosHTML::yesnoRadioList( 'xfaq[notify]', 'class="inputbox"', $xfaq['notify'] );
	$yn_xfaq_thankuser = mosHTML::yesnoRadioList( 'xfaq[thankuser]', 'class="inputbox"', $xfaq['thankuser'] ); ?>

    <form action="index2.php" method="post" name="adminForm" id="adminForm">
		<table cellpadding="2" cellspacing="0" border="0" width="100%">
			<tr>
    			<td width="40%" class="sectionname">
      				<?php echo _XFAQ_XFAQ; ?>
      			</td>
      			<td valign="middle" align="bottom" style="font-size:10px; vertical-align:baseline;">
                    [&nbsp;
                    <?php echo $xfaqMess; ?>
                    &nbsp;]
    			</td>
  			</tr>
		</table>

		<table width="100%" border="0" cellpadding="2" cellspacing="0" class="adminForm">
			<tr>
				<td>
		            <?php
                    $tabs = new mosTabs(0);
                    $tabs->startPane( 'component' );
                    $tabs->startTab( _XFAQ_A_TAB_GENERAL, 'general' ); ?>

                    <table width="100%" border="0" cellpadding="2" cellspacing="0" class="adminForm">
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_A_INDEX_MODE; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_indexmode; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_A_INDEX_MODE_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_ENTRIES_PER_PAGE; ?></td>
                            <td align="left" valign="top">
                                <input type="text" name="xfaq_perpage" value="<?php echo $xfaq['perpage']; ?>" size="5" />
                                &nbsp;
                                <?php
                                $tip = _XFAQ_ENTRIES_PER_PAGE_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_SHOW_SEARCH_BOX; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_showsearch; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_A_SEARCH_BOX_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_SHOW_CATEGORIE; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_showcategories; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_CATEGORIE_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_SHOW_AUTHOREN_DETAILS;; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_hideauthor; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_SHOW_AUTHOREN_DETAILS_TIP;;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_INTRO_TEXT; ?></td>
                            <td align="left" valign="top">
                                <textarea cols="70" rows="4" name="xfaq[introtext]" class="inputbox" wrap='virtual'><?php echo $xfaq['introtext']; ?></textarea>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_INTRO_TEXT_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                    </table>
                    <?php
                    $tabs->endTab();
                    $tabs->startTab( _XFAQ_A_TAB_ENTRY, 'entry' ); ?>
                    <table width="100%" border="0" cellpadding="4" cellspacing="2" class="adminForm">
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_REQUEST_AUTHOR_NAME; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_requestauthorname; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ__XFAQ_REQUEST_AUTHOR_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_REQUEST_AUTHOR_LOCATION; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_requestauthorlocation; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_REQUEST_AUTHOR_LOCATION_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_AUTHOR_PAGES; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_requestauthorhomepage; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_AUTHOR_PAGES_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_AUTHOR_MAIL; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_requestauthoremail; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_AUTHOR_MAIL_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_ANSWER_REQUIRED; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_answermandatory; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_ANSWER_ENTRIES;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_ANSWER_BOX; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_requestanswer; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_ANSWER_BOX_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_ALLOW_COMMENTS; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_allowcomments; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_ALLOW_COMMENTS_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_HTML_EDITOR; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_usehtmleditor; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_HTML_EDITOR_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                    </table>
                    <?php
                    $tabs->endTab();
                    $tabs->startTab( _XFAQ_A_TAB_PUBLISH, 'publish' ); ?>
                    <table width="100%" border="0" cellpadding="4" cellspacing="2" class="adminForm">
                    	<tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_ALLOW_ENTRIES; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_allowentry; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_ALLOW_ENTRIES_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_ANONYME_ENTRIES; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_anonentry; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_ANONYME_ENTRIES_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_AUTO_ENTRIES; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_autopublish; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_AUTO_ENTRIES_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_NOTIFY_WEBMASTER; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_notify; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_NOTIFY_WEBMASTER_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_WEBMASTER_MAIL; ?></td>
                            <td align="left" valign="top">
                                <input type="text" name="xfaq[notify_email]" value="<?php echo $xfaq['notify_email']; ?>" size="40" />
                                &nbsp;
                                <?php
                                $tip = _XFAQ_WEBMASTER_MAIL_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_THANK_USER; ?></td>
                            <td align="left" valign="top">
                                <?php echo $yn_xfaq_thankuser; ?>
                                &nbsp;
                                <?php
                                $tip = _XFAQ_THANK_USER_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top" width="120"><?php echo _XFAQ_EXCL_CAT; ?></td>
                            <td align="left" valign="top">
                                <input type="text" name="xfaq[exclcat]" value="<?php echo $xfaq['exclcat']; ?>" size="3" />
                                &nbsp;
                                <?php
                                $tip = _XFAQ_EXCL_CAT_TIP;
                                echo mosToolTip( $tip ); ?>
                            </td>
                        </tr>
                    </table>
                    <?php
                    $tabs->endTab();
                    $tabs->startTab( _XFAQ_A_TAB_VERSION, 'version' ); ?>
                    <table width="100%" border="0" cellpadding="2" cellspacing="2" class="adminForm">
                    	<tr>
                            <td width="150" align="left" valign="top"><?php echo _XFAQ_INSTALLED_VER; ?></td>
                            <td align="left" valign="top">
                                <span style="font-align:left; font-size:10px; color:#000099; font-weight:bold;"><?php echo xfaq_this_version(); ?></span>
                            </td>
                        </tr>
                        <?php
                        $xmlError = true;
                        require_once( $GLOBALS['mosConfig_absolute_path'] . '/includes/domit/xml_domit_rss_lite.php' );
                        $vFile = 'http://www.mgfi.info/customer/versions/xfaq.xml';
                        $handle = fopen( $vFile, 'rb' );
                        if( $handle ){
                            $rssDoc = &new xml_domit_rss_document_lite( $cacheTime = 0 );
                            $rssDoc->loadRSS( $vFile );
                            $totalChannels = $rssDoc->getChannelCount();
                            // check and define language
                            $tmpLang = $GLOBALS['mosConfig_lang'];
                            if( isset( $GLOBALS['mosConfig_alang'] ) && !empty( $GLOBALS['mosConfig_alang'] )){
                                $tmpLang = $GLOBALS['mosConfig_alang'];
                            }

                            $channelLang = '';
                            for( $i = 0; $i < $totalChannels; $i++ ) {
                                $currChannel = &$rssDoc->getChannel( $i );
                                if( strpos( $currChannel->getTitle(), $tmpLang ) === 0 ){
                                    $channelLang = $tmpLang;
                                    break;
                                }
                            }
                            if( !$channelLang ){
                                $channelLang = 'default';
                                for( $i = 0; $i < $totalChannels; $i++ ) {
                                    $currChannel = &$rssDoc->getChannel( $i );
                                    if( $currChannel->getTitle() === $channelLang ){
                                        break;
                                    }
                                }
                            }
                            if( $currChannel->getTitle() === $channelLang ){
                                $xmlError = false;
                                $actualItems = $currChannel->getItemCount();
                                if( $actualItems != 0 ){
                                    for( $j = 0; $j < $actualItems; $j++ ) {
                                        $currItem = &$currChannel->getItem( $j ); ?>
                                        <tr>
                                            <td valign="top"><?php echo $currItem->getTitle(); ?></td>
                                            <td>
                                                <?php
                                                if( $currItem->getTitle() == 'Version' ){
                                                    if( $currItem->getDescription() === xfaq_this_version() ){ ?>
                                                        <span style="font-align:left; font-size:10px; color:#000099; font-weight:bold;">
                                                        <?php
                                                    }else{ ?>
                                                        <span style="font-align:left; font-size:10px; color:#FF0000; font-weight:bold;">
                                                        <?php
                                                    }
                                                    echo $currItem->getDescription(); ?>
                                                    </span>
                                                    <?php
                                                }else{
                                                    if( $currItem->getLink() ){
                                                        echo '<a href="' . $currItem->getLink() . '" target="_blank">' . $currItem->getTitle() . '</a>';
                                                    }else{
                                                        echo $currItem->getDescription();
                                                    }
                                                } ?>
                                            </td>
                                        </tr>
                                        <?php
                                    } // end for actualitems
                                } // end if actualitems
                            } // end lang selector
                        }else{
                            $xmlError = true;
                        } // end handle

                        if( $xmlError ){ ?>
                            <tr>
                                <td colspan="2"><?php echo _XFAQ_INFO_NOT_AVAIL; ?></td>
                            </tr>
                            <?php
                        } ?>
                    </table>
                	<?php
                    $tabs->endTab();
                    $tabs->startTab( _XFAQ_A_TAB_ABOUT, 'about' ); ?>
                    <table width="100%" border="0" cellpadding="2" cellspacing="2" class="adminForm">
                        <tr>
                        	<td>
                        		<fieldset><legend><?php echo _XFAQ_XFAQ; ?></legend>
                            		<table>
                                		<tr>
                                			<td>
                                                <span style="font-size:12px; color:#000099; font-weight:bold;">XfaQ</span> basiert auf der Komponente SimpleFAQ v.2.0.1 von parkviewconsultants, welche wiederum auf der Glossarykomponente von Sascha Claren basiert.<br />
                                                Wir entschlossen uns daraus XfaQ zu erstellen, da alle Scripte teilweise masiv umgestellt und auf den neuesten Stand gebracht wurden.<br />
                                                Zudem wurden etliche Fehler sowie das gesamte Interface erneuert.
                                            </td>
                                		</tr>
                                		<tr>
                                			<td align="left">
                                                <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
                                                    <input type="hidden" name="cmd" value="_s-xclick" />
                                                    <input type="image" src="https://www.paypal.com/de_DE/i/btn/x-click-butcc-donate.gif" border="0" name="submit" alt="Unterst&uuml;tzen sie uns - zahlen Sie mit PayPal" title="Unterst&uuml;tzen sie uns" />
                                                    <input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIHPwYJKoZIhvcNAQcEoIIHMDCCBywCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BC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Z3gRtPqhP6NMjlSwrIudVwB8cAi8O3GaTkVnv9pf3mJzN8eVjlEmUJ8MzWe0Cc0ZusrLcGfo8hCi+pbte9bO+zswhysbUZMC002d/5v2l/pu4=-----END PKCS7-----">
                                                </form>
                        					</td>
                                		</tr>
                                	</table>
                                </fieldset>
                            </td>
                        </tr>
                        <tr>
                        	<td>
                        		<fieldset><legend><?php echo 'Original'; ?></legend>
                            		<table>
                                        <tr>
                                            <td>
                                                Hier der Originalwortlaut der Lizenz sowie des Copyrights:
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <p><b>SimpleFAQ</b><br>
                                                <p>The SimpleFAQ component was based heavily on Sascha Claren (www.mamboaddons.com) Glossary component
                                                <p><b>License</b><br>
                                                SimpleFAQ is free software; you can redistribute it and/or modify it under the terms
                                                of the <a href="http://www.gnu.org/licenses/gpl.html" target="_blank">GNU General
                                                Public License</a> as published by the Free Software Foundation. This program is
                                                distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
                                                even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
                                                See the GNU General Public License for more details.<P>
                                                <p>All upcoming versions are developed and released by
                                                Rick Chapman ( <a href="http://www.parkviewconsultants.com" target="_blank">www.parkviewconsultants.com </a> )</p>
                                            </td>
                                        </tr>
                                    </table>
                                </fieldset>
                            </td>
                        </tr>
                    </table>
	               	<?php
                    $tabs->endTab();
                    $tabs->endPane(); ?>
                </td>
            </tr>
        </table>
        <input type="hidden" name="id" value="">
        <input type="hidden" name="task" value="">
        <input type="hidden" name="xfaq[beginwith]" value="all">
        <input type="hidden" name="option" value="<?php echo $option; ?>">
    </form>
	<?php
}

function saveConfig( $option ) {
    global $my, $xfaq, $xfaq_perpage;

    $configfile = $GLOBALS['mosConfig_absolute_path'] . '/administrator/components/com_xfaq/config.xfaq.php';
    @chmod( $configfile, 0777 );
    $permission = @is_writable( $configfile );
    if( !$permission ) {
    	@chmod( $configfile, 0644 );
    	mosRedirect( 'index2.php?option=' . $option . '&task=config', _XFAQ_CONFIG_NOT_WRITEABLE );
		break;
    }

    $config = "<?php\n";
    $config .= '// Configurationfile [ XfaQ ] for ' . $GLOBALS['mosConfig_sitename'] . ' at ' . $GLOBALS['mosConfig_live_site']. "\n";
	$config .= '// saved at: '.date( 'Y.m.d - G:i:s', time() ) .' - by: '.$my->username.'( '. $my->id.' )'."\n\n";
    $config .= "// Variables for Publishing\n";
    $config .= '$xfaq[\'allowentry\'] = \'' . $xfaq['allowentry'] . "';\n";
    $config .= '$xfaq[\'anonentry\'] = \'' . $xfaq['anonentry'] . "';\n";
    $config .= '$xfaq[\'autopublish\'] = \'' . $xfaq['autopublish'] . "';\n";
    $config .= '$xfaq[\'notify\'] = \'' . $xfaq['notify'] . "';\n";
    $config .= '$xfaq[\'notify_email\'] = \'' . $xfaq['notify_email'] . "';\n";
    $config .= '$xfaq[\'thankuser\'] = \'' . $xfaq['thankuser'] . "';\n";
    $config .= '$xfaq[\'exclcat\'] = \'' . $xfaq['exclcat'] . "';\n";

    $config .= "\n";
    $config .= "// Variables for Display\n";
    $config .= '$xfaq[\'indexmode\'] = \'' . $xfaq['indexmode'] . "';\n";
    $config .= '$xfaq[\'perpage\'] = \'' . $xfaq_perpage . "';\n";
    $config .= '$xfaq[\'sorting\'] = \'' . $xfaq['sorting'] . "';\n";
    $config .= '$xfaq[\'showrating\'] = \'' . $xfaq['hidedef'] . "';\n";
    $config .= '$xfaq[\'hideauthor\'] = \'' . $xfaq['hideauthor'] . "';\n";
    $config .= '$xfaq[\'showcategories\'] = \'' . $xfaq['showcategories'] . "';\n";
    $config .= '$xfaq[\'beginwith\'] = \'' . $xfaq['beginwith'] . "';\n";
    $config .= '$xfaq[\'allowcomments\'] = \'' . $xfaq['allowcomments'] . "';\n";
    $config .= '$xfaq[\'showsearch\'] = \'' . $xfaq['showsearch'] . "';\n";
    $config .= '$xfaq[\'introtext\'] = \'' . $xfaq['introtext'] . "';\n";
    $config .= "\n";
    $config .= "// Variables for Data Entry\n";
    $config .= '$xfaq[\'requestauthorname\'] = \'' . $xfaq['requestauthorname'] . "';\n";
    $config .= '$xfaq[\'requestauthorlocation\'] = \'' . $xfaq['requestauthorlocation'] . "';\n";
    $config .= '$xfaq[\'requestauthorhomepage\'] = \'' . $xfaq['requestauthorhomepage'] . "';\n";
    $config .= '$xfaq[\'requestauthoremail\'] = \'' . $xfaq['requestauthoremail'] . "';\n";
    $config .= '$xfaq[\'answermandatory\'] = \'' . $xfaq['answermandatory'] . "';\n";
    $config .= '$xfaq[\'requestanswer\'] = \'' . $xfaq['requestanswer'] . "';\n";
    $config .= '$xfaq[\'usehtmleditor\'] = \'' . $xfaq['usehtmleditor'] . "';\n";
    $config .= "?>";

    if( $fp = @fopen( $configfile, 'wb' )) {
        @fputs( $fp, $config, strlen( $config ));
        @fclose( $fp );
        @chmod( $configfile, 0644 );
    }
    mosRedirect( 'index2.php?option=' . $option . '&task=config', _XFAQ_CONFIG_SAVED);
}
?>